home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / pipeline / abacus / p_line / Custom02 / c_Add < prev    next >
Encoding:
Text File  |  1992-04-26  |  6.1 KB  |  421 lines

  1. %OP%VS4.12 (10-Feb-92), Gerald Fitton, R4000 2915 6625 6368 
  2. %OP%TNN
  3. %OP%DP0
  4. %OP%IRY
  5. %OP%PL0
  6. %OP%HM0
  7. %OP%FM0
  8. %OP%BM0
  9. %OP%LM4
  10. %OP%PT1
  11. %OP%PDPipeLine
  12. %OP%WC2,1238,44,980,0,21,0,21
  13. %OP%NDn_01,B123
  14. %OP%NDn_02,B124
  15. %OP%FR0,2
  16. %CO:A,60,72%Comments and Commands
  17.  
  18. ------------------------------------------------------------------------
  19.  
  20. Function "add_anything"
  21.  
  22. Although this custom function could be considerably simplified, it does 
  23. illustrate many points which are fundamental (see the ReadMe file).  It 
  24. accepts a parameter called "p_01" (which must be a number) and returns 
  25. (p_01 + 1).  You can change the number added by changing the second 
  26. argument of the command - set_value(B25,1) - of slot A25.  Try changing 
  27. slot A25 to set_value(B25,2).  If you disable - set_value(B25,1) - in 
  28. A25 then you can enter a value directly into B25.
  29.  
  30. The commands in slots A34A36 are unnecessary to the execution of the 
  31. custom function.  They write the current values of slots A25, A28 and 
  32. A31 to C25, C28 and C31 respectively.  By doing this you can see what 
  33. values were contained in them at the time the set_value(C#,A#) command 
  34. was executed.  If your custom function has 'bugs' then you will find 
  35. such lines helpful.
  36.  
  37. %V%%L%function("add_anything","p_01:number")
  38.  
  39. Use the slot B25 as a local value
  40. %V%%L%set_value(B25,1)
  41.  
  42. What value has the parameter?
  43. %V%%L%@p_01
  44.  
  45. Process the data: find (p_01 + B25)
  46. %V%%L%@p_01+B25
  47.  
  48. Keep track of what's happening
  49. %V%%L%set_value(C25,B25)
  50. %V%%L%set_value(C28,A28)
  51. %V%%L%set_value(C31,A31)
  52.  
  53. Return the result
  54. %V%%L%result(A31)
  55. ------------------------------------------------------------------------
  56.  
  57. Function "use_slots"
  58.  
  59. This custom function accepts two parameters called "p_01" and "p_02" 
  60. and adds them together before returning the result.  Again, adding two 
  61. parameters together could be greatly simplified to the single line - 
  62. ... return(@@p_01+@@p_02) - but, as it is written, it does illustrate 
  63. some useful points (see the ReadMe file).  The - set_value(C#,A#) - 
  64. commands in A76A79 keep track of the values taken by the slots in the A 
  65. column.  The 'commands' @@p_01 & @@p_02 in A61A62 hold the parameter 
  66. values.  As in the previous custom function, this does enable you to 
  67. see what is happening and it is useful for debugging.  In A65A66 the 
  68. two parameters are addigned to two 'local' variables, the slots B65 
  69. &B66.  The values of the local variables are changed by the commands in 
  70. A69A70 before they are added in A73.  Note that the parameters require 
  71. an @@ symbol to convert the string, "p_01" to the number @@p_01.
  72.  
  73. %V%%L%function("use_slots","p_01:number","p_02:number")
  74.  
  75. What values have the parameters?
  76. %V%%L%@p_01
  77. %V%%L%@p_02
  78.  
  79. Assign the values of the parameters to local variables
  80. %V%%L%set_value(B65,@p_01)
  81. %V%%L%set_value(B66,@p_02)
  82.  
  83. Change the values of the 'local' variables B65 & B66
  84. %V%%L%set_value(B65,B65+1)
  85. %V%%L%set_value(B66,B66-1)
  86.  
  87. Process the data by adding the slots (B65 + B66)
  88. %V%%L%B65+B66
  89.  
  90. Keep track of what's happening
  91. %V%%L%set_value(C61C62,A61A62)
  92. %V%%L%set_value(C65C66,A65A66)
  93. %V%%L%set_value(C69C70,A69A70)
  94. %V%%L%set_value(C73,A73)
  95.  
  96. Return the result
  97. %V%%L%result(A73)
  98. ------------------------------------------------------------------------
  99.  
  100. Function "use_names"
  101.  
  102. This custom function introduces the use of a 'name' for a variable.  
  103. Two 'names', "n_01" and "n_02" are declared by the 
  104. set_name("name",slotref) commands in slots A123 & A124.  When a 'name' 
  105. is declared in a custom function it is good practice to assign a slot 
  106. rather than a value to the name.  In this case the slots B123 & B124 
  107. have been assigned to the 'names' "n_01" and "n_02" respectively.
  108.  
  109. In a custom function a 'name' must be declared only once.  The 'name' 
  110. is declared with the command - set_name(name,slotref).  After declaring 
  111. the 'name' of the variable you may assign a new value to that 'name' as 
  112. many times as you wish using the command - set_value(name,value).  When 
  113. you change the value of a name the value in the slots assigned to that 
  114. name will also change.
  115.  
  116. The commands in slots A127 & A128 assign the values of the two 
  117. parameters, "p_01" & "p_02" to the two names "n_01" & "n_02".  Notice 
  118. that when this command is executed new values of the 'names' are 
  119. relayed to and stored in the two slots B123 & B124.  The command in 
  120. A138, - set_value(C123C124,A123A124), is included to show that the 
  121. values in A123 & A124 are not changed by the commands in A127, A128, 
  122. A131 & A132!  However, these last four commands do change the values of 
  123. the two 'names' and the values in the slots B123 & B124.
  124.  
  125. Contrast the use of 'names' in this custom function with the use of 
  126. parameters in "use_slots".  Values such as "p_01" have to be written as 
  127. @@p_01 to become a value whereas the 'name' "n_01" is a value when 
  128. written as n_01.  The command set_name("name",slotref) requires 
  129. inverted commas around the 'name' because, within the set_name command, 
  130. "n_01" is a text string.  The addition, n_01+n_02, in slot A135 does 
  131. not require inverted commas around the 'names' nor do the 'names' need 
  132. to be preceded by @@; n_01 is the value taken by the 'name' "n_01".
  133.  
  134.  
  135. %V%%L%function("use_names","p_01:number","p_02:number")
  136.  
  137. Declare the 'names' of the variables and the slots they will use
  138. %V%%L%set_name("n_01",B123)
  139. %V%%L%set_name("n_02",B124)
  140.  
  141. Assign values to the named variables
  142. %V%%L%set_value(n_01,@p_01)
  143. %V%%L%set_value(n_02,@p_02)
  144.  
  145. Modify the values of the named variables
  146. %V%%L%set_value(n_01,n_01+1)
  147. %V%%L%set_value(n_02,n_02-1)
  148.  
  149. Process the data by finding (n_01 + n_02)
  150. %V%%L%n_01+n_02
  151.  
  152. Keep track of what's happening
  153. %V%%L%set_value(C123C124,A123A124)
  154. %V%%L%set_value(C127C128,A127A128)
  155. %V%%L%set_value(C131C132,A131A132)
  156. %V%%L%set_value(C135,A135)
  157.  
  158. Return the result
  159. %V%%L%result(A135)
  160. ------------------------------------------------------------------------
  161. %CO:B,6,0%Value
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. %V%%R%1
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. %V%%R%2
  226. %V%%R%1
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283. %V%%R%2
  284. %V%%R%1
  285. %CO:C,6,0%
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309. %V%%R%1
  310.  
  311.  
  312. %V%%R%0
  313.  
  314.  
  315. %V%%R%1
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345. %V%%R%1
  346. %V%%R%2
  347.  
  348.  
  349. %V%%R%1
  350. %V%%R%2
  351.  
  352.  
  353. %V%%R%2
  354. %V%%R%1
  355.  
  356.  
  357. %V%%R%3
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407. %V%%R%3
  408. %V%%R%4
  409.  
  410.  
  411. %V%%R%1
  412. %V%%R%2
  413.  
  414.  
  415. %V%%R%2
  416. %V%%R%1
  417.  
  418.  
  419. %V%%R%3
  420. %V%%R%""
  421.